import React from 'react'
import PubSub from 'pubsub-js'
import './Header.css'
export default function Header() {
  return (
    <div className="todo-header">
      <input
        type="text"
        onKeyDown={(e) => {
          const value = e.target.value.trim()
          //如果不是回车,或输入内容为空则返回
          if (e.key !== 'Enter' || !value) return

          PubSub.publish('add', value)
          //清除文本框内容'
          e.target.value = ''
        }}
      />
    </div>
  )
}
